package com.xxxx.portal.controller;

import com.xxxx.rpc.pojo.Admin;
import com.xxxx.rpc.pojo.CartList;
import com.xxxx.rpc.service.CartService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * 页面跳转
 *
 * @author zhoubin
 * @since 1.0.0
 */
@Controller
@RequestMapping("cart")
public class CartController {


    @Reference(interfaceClass = CartService.class)
    private CartService cartService;

    /**
     * 页面跳转
     * @param page
     * @return
     */
    @RequestMapping("/{page}")
    public String page(@PathVariable String page) {
        return page;
    }

    @RequestMapping("getCartNum")
    @ResponseBody
    public String getCartNum(HttpServletRequest request , Model model){
        Admin admin = (Admin) request.getSession().getAttribute("user");
        CartList cartList = cartService.getCartAllList(admin);
        model.addAttribute("cartList" , null == cartList? new CartList() : cartList);
        return "cart/list";
    }

    @RequestMapping("getCartList")
    public String getCartList(HttpServletRequest request , Model model){
        Admin admin = (Admin) request.getSession().getAttribute("user");
        CartList cartList = cartService.getCartAllList(admin);
        model.addAttribute("cartList" , null == cartList? new CartList() : cartList);
        return "cart/list";
    }

}